﻿using IDAdmin.Common;
using IDAdmin.Lib.DataLayer;
using IDAdmin.Lib.UI;
using IDAdmin.Lib.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



namespace IDAdmin.Pages
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //List<string> name = new List<string>();
            //List<long> listFill = WebDB_N.getFill();
            //Dictionary<long, string> listChar = WebDB_N.getLevel();
            //Table table = new Table();
            //foreach (var item in listFill)
            //{
            //    foreach (var row in listChar)
            //    {
            //        if (item == row.Key)
            //        {
            //            TableRow aaa = new TableRow();
            //            //    if (item.Value.Count == 3)
            //            //  {

            //            aaa.Cells.AddRange
            //            (
            //                new TableCell[]
            //                        {
            //                            UIHelpers.CreateTableCell(row.Value.ToString(),HorizontalAlign.Center,"")        
            //                        }
            //            );
            //            table.Rows.Add(aaa);
            //            //name.Add(row.Value);
            //        }
            //    }
            //}           
            //Panel1.Controls.Add(table);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //WebDB.updatecasgs();
            // string day = "";
            //bool status = WebDB.InsertGoldShopDataToSqlserver(day);
            string SAF=CryptHelper.EncodeMD5("FSAFASF");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            WebDB.getAu(dateTimeList);
        }



        protected void ccuButton3_Click(object sender, EventArgs e)
        {
            DateTime day = DateTime.Now;
            string yesterday = AddWorkdays(day, -1).ToString("MM/dd/yyyy");
            // bool s = WebDB.InsertALLCcuCasToSqlserver();
            bool status = WebDB_N.InsertCcuCasToSqlserver(yesterday);
        }


        protected void auButton4_Click(object sender, EventArgs e)
        {
            //WebDB.InsertNAU();
            string day = DateTime.Now.ToString("MM/dd/yyyy");
            //day = "04/08/2015 00:00:00";
            bool status = WebDB_N.InsertAuCasToSqlserver(day);
        }

        protected void Button5_Click(object sender, EventArgs e)
        {           
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(DateTime.Today, DateTime.Today);
            //string day = Request.QueryString["day"].ToString();
            bool status = WebDB_N.InsertGoldShopDataToSqlserver(dateTimeList);
        }


        public static DateTime AddWorkdays(DateTime originalDate, int workDays)
        {
            DateTime tmpDate = originalDate;
            int a = workDays > 0 ? 1 : -1;
            while (workDays != 0)
            {
                tmpDate = tmpDate.AddDays(a);
                workDays -= a;
                //workDays--;
            }
            return tmpDate;
        }

        protected void checkccuButton3_Click(object sender, EventArgs e)
        {
            ////DateTime day = DateTime.Today;
            ////DateTime yesterday = AddWorkdays(day, -1);
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            bool a = WebDB_N.checkCCU(dateTimeList[0]);
        }

        protected void pcardButton3_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            bool a = WebDB_N.InsertPcard(dateTimeList[0]);
        }

        protected void buttonTestTime_Click(object sender, EventArgs e)
        {
           int ROE= LevelSaveStatsWebDB.testA7(new DateTime(2015, 5, 25));
        }

        protected void InsertStatsConsumeButton3_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            bool a = WebDB_N.InsertStatsComsume(dateTimeList);
        }

        protected void changetimeButton3_Click(object sender, EventArgs e)
        {
            DateTime result = WebDB_N.UnixTimeStampToDateTime(Convert.ToDouble(timestampTextBox1.Text));
            datetimeLabel1.Text = result.ToString();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            string SAF = CryptHelper.EncodeMD5("FSAFASF");
        }
      
    }
}